(function() {
  var __hasProp = {}.hasOwnProperty,
    __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor(); child.__super__ = parent.prototype; return child; };

  this.ScrollPagingView = (function(_super) {

    __extends(ScrollPagingView, _super);

    function ScrollPagingView() {
      return ScrollPagingView.__super__.constructor.apply(this, arguments);
    }

    ScrollPagingView.prototype.initialize = function() {
      var _this = this;
      ScrollPagingView.__super__.initialize.apply(this, arguments);
      console.log("ScrollPagination initialize");
      return $(window).on("scroll", function() {
        var mayLoadContent;
        if (_this.isEnabled) {
          mayLoadContent = $(document).scrollTop() + $(window).height() >= $(_this.el).height();
          if (mayLoadContent) {
            return _this.startLoading();
          }
        }
      });
    };

    ScrollPagingView.prototype.heightOffset = 355;

    ScrollPagingView.prototype.isEnabled = true;

    ScrollPagingView.prototype.renewScrolling = function() {
      return this.isEnabled = true;
    };

    ScrollPagingView.prototype.startLoading = function() {
      var _this = this;
      $(this.el).append("<div class='scroll-loading'></div>");
      this.isEnabled = false;
      return $.ajax({
        type: 'POST',
        url: this.model.url(),
        success: function(data) {
          _this.model.set("Page", _this.model.get("Page") + 1, {
            silent: true
          });
          _this.afterLoad(data);
          if (data.length) {
            return _this.isEnabled = true;
          }
        },
        complete: function() {
          return _this.removeScrollLoading();
        }
      });
    };

    ScrollPagingView.prototype.removeScrollLoading = function() {
      return $(this.el).find(".scroll-loading").remove();
    };

    return ScrollPagingView;

  })(CustomView);

}).call(this);
